﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;
using CNotebook.Inventory;

namespace NotebookS2
{
    public partial class AddMeasure : RibbonForm
    {
        public AddMeasure()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }

        public string ItemCode { get; set; }
        public string ItemName { get; set; }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            UoMUnit oUnit = new UoMUnit();

            oUnit.ItemCode = this.ItemCode;
            oUnit.ItemName = this.ItemName;
            oUnit.UnitMeasure = txtUoM.Text;
            oUnit.BarCode = txtBarCode.Text;
            oUnit.Description = txtDscription.Text;
            oUnit.ConversionQty = Convert.ToDouble(txtConvQty.Text);
            oUnit.SmallestConversionQty = Convert.ToDouble(txtSmallestConv.Text);
            if (cboDefaultUoM.SelectedIndex == 0)
            {
                oUnit.DefaultUoM = true;
            }
            else
            {
                oUnit.DefaultUoM = false;
            }

            UoMManager oManager = new UoMManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();

            if (oManager.IsUoMExists(this.ItemCode, txtUoM.Text) == false)
            {
                oManager.AddMeasure(oUnit);
                this.Close();
            }
            else
            {
                MessageBox.Show("Unit measure is already exists in this item!!!!", "Unit Measure", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtUoM.Focus();
                txtUoM.SelectAll();
            }

            oManager.Close();

            
        }

        private void AddMeasure_Load(object sender, EventArgs e)
        {
            cboDefaultUoM.SelectedIndex = 0;
        }
    }
}
